package com.isay.app.honey.ui.modify;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.JsonObject;
import com.isay.app.honey.R;
import com.isay.app.honey.manager.NetworkManager;
import com.isay.app.honey.ui.regist.RegisterActivity;
import com.isay.frameworklib.okhttp.ICommonCallback;
import com.isay.frameworklib.ui.BaseActivity;
import com.isay.frameworklib.user.UserManager;
import com.isay.frameworklib.utils.ToastUtils;

import org.json.JSONObject;

public class ModifyPwdActivity extends BaseActivity implements View.OnClickListener {

    private EditText mEdtPwdOld;
    private EditText mEdtPwdNew;
    private EditText mEdtPwdNewSure;

    public static void launch(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, ModifyPwdActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_modify_pwd);
        initView();
    }

    private void initView() {
        ((TextView) findViewById(R.id.tv_title)).setText("修改密码");
        findViewById(R.id.iv_go_back).setOnClickListener(this);
        findViewById(R.id.btn_commit).setOnClickListener(this);
        mEdtPwdOld = findViewById(R.id.edt_pwd_old);
        mEdtPwdNew = findViewById(R.id.edt_pwd_new);
        mEdtPwdNewSure = findViewById(R.id.edt_pwd_new_sure);
    }

    @Override
    protected int getStatusBarColor() {
        return 0;
    }

    @Override
    protected void onCreateActivity(Bundle savedInstanceState) {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_go_back:
                finish();
                break;
            case R.id.btn_commit:
                modifyPwd();
                break;
            default:
                break;
        }
    }


    //修改密码中
    private void modifyPwd() {
        showLoading("修改密码中...");
        NetworkManager.modifyPwd(mEdtPwdOld.getText().toString(), mEdtPwdNew.getText().toString(), mEdtPwdNewSure.getText().toString(), new ICommonCallback() {
            @Override
            public void onSuccess(int ret, String msg, String content) {
                dismissDialog();
                if (ret == 200) {
                    Toast.makeText(ModifyPwdActivity.this, msg, Toast.LENGTH_SHORT).show();
                } else {
                    ToastUtils.show(msg);
                }
            }

            @Override
            public void onFailure(Exception e) {
                dismissDialog();
                ToastUtils.show(e.toString());
            }
        });
    }
}
